/**
 * Created by smp on 2017/5/2.
 */
$("#contractRecordSave").on("click",function () {
    var contractName=$("#contractName").textbox("getValue");
    var beginDate=$("#beginDate").datebox("getValue");
    var endDate=$("#endDate").datebox("getValue");
    if(beginDate==null||beginDate==''){
        return;
    }
    if(endDate==null||endDate==''){
        return;
    }
    var selected={contractName:contractName,beginDate:beginDate,endDate:endDate};
    parent.getContractRecord(selected);
    parent.layer.close(parent.layer.getFrameIndex(window.name));
});
/**
 * 时间限制
 * @param month
 * @returns {*}
 */
function toMonth(month) {
    month=month+1;
    if(month<10)
        return "0"+month;
    else
        return month;
}
function toDate(date) {
    if(date<10)
        return "0"+date;
    else
        return date;
}
var beginTime=$("#beginTime").val();
var endTime=$("#endTime").val();
$(function(){
    $("#beginDate").datebox().datebox("calendar").calendar({
        validator:function(date){
            var dateTime=date.getFullYear()+"-"+toMonth(date.getMonth())+"-"+toDate(date.getDate());
            var endDate=$("#endDate").textbox("getValue");
            if(endDate==null||endDate==""){
                return beginTime<=dateTime&&dateTime<=endTime;
            }else {
                return beginTime<=dateTime&&dateTime<=endTime&&dateTime<=endDate;
            }
        }
    });
    $("#endDate").datebox().datebox("calendar").calendar({
        validator:function(date){
            var dateTime=date.getFullYear()+"-"+toMonth(date.getMonth())+"-"+toDate(date.getDate());
            var beginDate=$("#beginDate").textbox("getValue");
            if(beginDate==null||beginDate==""){
                return beginTime<=dateTime&&dateTime<=endTime;
            }else {
                return beginTime<=dateTime&&dateTime<=endTime&&dateTime>=beginDate;
            }
        }
    });
});
